package com.example.newnoke.ui;

import android.content.DialogInterface;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.view.View;

import com.example.newnoke.R;
import com.example.newnoke.data.BaseDatas;
import com.example.newnoke.databinding.ActivityTixianBinding;
import com.example.newnoke.mvp.presenter.TestPresenter;
import com.example.newnoke.mvp.view.ITestV;
import com.example.newnoke.utils.API;
import com.example.newnoke.utils.MyDialogTool;
import com.geya.jbase.baseactivity.BaseDetailsActivity;
import com.geya.jbase.constant.RequestType;
import com.geya.jbase.uiview.ToastUtil;

import java.util.HashMap;

public class TiXianActicity extends BaseDetailsActivity<TestPresenter> implements ITestV {

    private ActivityTixianBinding mBinding;

    @Override
    public TestPresenter newPresenter() {
        return new TestPresenter(this);
    }

    @Override
    public void init() {
       mTitleButton.setTitles("提现");
       mTitleButton.setRButtonText("提现记录");
       mTitleButton.setRButtonClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               startActivity(new Intent(TiXianActicity.this,TXJLActivity.class));
           }
       });
       mBinding.yue.setText("￥"+getIntent().getStringExtra("yue"));


       mBinding.pay.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               if (!mBinding.num.getText().toString().isEmpty()) {
                   int nums = Integer.parseInt(mBinding.num.getText().toString());
                   MyDialogTool.TiShi(TiXianActicity.this,
                           "转入提示",
                           "确认提现"+nums+"元？",
                           "提现",
                           "取消",
                           new DialogInterface.OnClickListener() {
                               @Override
                               public void onClick(DialogInterface dialog, int which) {

                               }
                           }, new DialogInterface.OnClickListener() {
                               @Override
                               public void onClick(DialogInterface dialog, int which) {
                                   int num = Integer.parseInt(mBinding.num.getText().toString());
                                   HashMap<String, String> map = new HashMap<>();
                                   map.put("amounts",num+"");
                                   mPresenter.accessServers(RequestType.OKGO_POST, API.FORWARD, BaseDatas.class, map);
                               }
                           }).show();

               }else {
                   ToastUtil.showShort("请输入金额");
               }

           }
       });

    }

    @Override
    public void setContentView() {
        mBinding = DataBindingUtil.setContentView(this,R.layout.activity_tixian);
    }

    @Override
    public void getDatas(String json, String type) {
        ToastUtil.showShort(json);
       startActivity(new Intent(this,TXJLActivity.class));
       finish();
    }
}
